#include <iostream>
#include <stdlib.h>
typedef struct node{
    int data;
    node* next;
}node;

typedef struct set{
    node* head;
    int size;
}set;

unsigned short *createSet(set Set,int size){
    unsigned short *result=(unsigned short *)malloc(size*sizeof(unsigned short));
    node *now=Set.head;
    while (now!= NULL){
        result[now->data]=1;
        now=now->next;
    }
    return result;
}

set Union(unsigned short *a,unsigned short *b,int size){
    set result;
    result.head=NULL;
    result.size=0;
    node *now=result.head;
    for (int i=0; i<size; i++){
        if (a[i] || b[i]){
            node *next=(node *)malloc(sizeof(node));
            next->data=i;
            next->next=NULL;
            now->next=next;
            now=now->next;
            result.size++;
        }
    }
    return result;
}

set intersection(unsigned short *a,unsigned short *b,int size){
    set result;
    result.head=NULL;
    result.size=0;
    node *now=result.head;
    for (int i=0; i<size; i++){
        if (a[i] && b[i]){
            node *next=(node *)malloc(sizeof(node));
            next->data=i;
            next->next=NULL;
            now->next=next;
            now=now->next;
            result.size++;
        }
    }
    return result;
}
set differrence(unsigned short *a,unsigned short *b,int size){
    set result;
    result.head=NULL;
    result.size=0;
    node *now=result.head;
    for (int i=0; i<size; i++){
        if (a[i] &&!b[i]){
            node *next=(node *)malloc(sizeof(node));
            next->data=i;
            next->next=NULL;
            now->next=next;
            now=now->next;
            result.size++;
        }
    }
    return result;
}

int n,m;
int M;
int main(){
    std::cin>>n;
    set A;
    A.head=NULL;
    A.size=n;
    node *now=A.head;
    for (int i=0; i<n; i++){
        node *next=(node *)malloc(sizeof(node));
        std::cin>>next->data;
        next->next=NULL;
        now->next=next;
        now=now->next;

    }
    std::cin>>m;
    set B;
    B.head=NULL;
    B.size=m;
    now=B.head;
    for (int i=0; i<m; i++){
        node *next=(node *)malloc(sizeof(node));
        std::cin>>next->data;
        next->next=NULL;
        now->next=next;
        now=now->next;
    }
    unsigned short *a=createSet(A,M);
    unsigned short *b=createSet(B,M);
    set U=Union(a,b,M);
    set I=intersection(a,b,M);
    set D=differrence(a,b,M);
    
    node *nowU=U.head;
    while (nowU!=NULL){
        std::cout<<nowU->data<<" ";
        nowU=nowU->next;
    }
    node *nowI=I.head;
    while (nowI!=NULL){
        std::cout<<nowI->data<<" ";
        nowI=nowI->next;
    }
    node *nowD=D.head;
    while (nowD!=NULL){
        std::cout<<nowD->data<<" ";
        nowI=nowD->next;
    }
    return 0;
}